<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>菜品管理</title>
    <%-- 静态包含 base标签、css样式、jQuery文件 --%>
    <%@include file="/pages/common/head.jsp" %>

    <script type="text/javascript">
        $(function () {
            // 给a标签绑定删除事件，用于确定删除操作
            $("a.deleteBook").click(function () {
                /**
                 * confirm是确认提示框函数
                 * 参数是它的提示内容
                 * 它有两个按钮 一个确认 一个取消
                 * 返回true代表点击了，false代表取消
                 *
                 * 在事件function中有个this对象，可以获取到当前正在相应的dom对象，我们可以转成jquery对象，然后操作jquery对象获得父对象的父对象，就可以获取到food.name
                 */
                return confirm("你确定要删除 【" + $(this).parent().parent().find('td:first').text() + "】 吗？");
            })
        });


    </script>

    <style>
        .class_list a {
            border: 2px #666 solid;
            margin: auto 20px;
            padding: 10px;
            width: 50px;
            height: 30px;
            font-weight: 700;
            text-decoration: none;
        }
    </style>

</head>
<body>

<div id="header">
    <span class="wel_word">菜品管理系统</span>
    <div>
        <a href="orderServlet?action=searchAllOrder">订单管理</a>
        <a href="index.jsp">返回首页</a>
    </div>
</div>

<div id="main">
    <div class="class_list" style="margin-top: 20px;">
        <a href="manager/foodServlet?action=listLimitClass&id=1&food_id=1">川菜</a>
        <a href="manager/foodServlet?action=listLimitClass&id=1&food_id=2">粤菜</a>
        <a href="manager/foodServlet?action=listLimitClass&id=1&food_id=3">湘菜</a>
        <a href="manager/foodServlet?action=listLimit&id=1">所有菜品</a>
    </div>
    <table>
        <tr>
            <td>名称</td>
            <td>价格</td>
            <td>菜类</td>
            <td colspan="2">操作</td>
        </tr>

        <c:forEach items="${requestScope['msg']}" var="food">
            <tr>
                <td>${food.food_name}</td>
                <td>${food.price}</td>
                <c:if test="${food.food_id  == 1}">
                    <td>川菜</td>
                </c:if>
                <c:if test="${food.food_id  == 2}">
                    <td>粤菜</td>
                </c:if>
                <c:if test="${food.food_id  == 3}">
                    <td>湘菜</td>
                </c:if>
                <td><a href="manager/foodServlet?action=getFood&id=${food.id}">修改</a></td>
                <td><a class="deleteBook" href="manager/foodServlet?action=delete&id=${food.id}">删除</a></td>
            </tr>
        </c:forEach>

        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td><a href="pages/manager/food_edit.jsp">添加菜品</a></td>
        </tr>
    </table>
    <br>
    <div id="page_nav">
        <form action="manager/foodServlet" method="get">
            <span>当前页：${param['id']}页</span>&nbsp;&nbsp;

            <c:if test="${param['id']>1}">
                <a href="manager/foodServlet?action=listLimit&id=1">首页</a>
                <a href="manager/foodServlet?action=listLimit&id=${param["id"] - 1==0?1:param["id"] - 1}">上一页</a>
            </c:if>

            <c:forEach var="page" begin="1" end="${requestScope['pages']}" step="1">
                <a href="manager/foodServlet?action=listLimit&id=${page}">
                    <c:if test="${page==param['id']}"> 【${param['id']}】 </c:if>
                    <c:if test="${page!=param['id']}"> ${page} </c:if>
                </a>
            </c:forEach>

            <c:if test="${param['id']<requestScope['pages']}">
                <a href="manager/foodServlet?action=listLimit&id=${param["id"]==requestScope['pages']?param["id"]:param["id"] + 1}">下一页</a>
                <a href="manager/foodServlet?action=listLimit&id=${requestScope['pages']}">末页</a>
            </c:if>

            共${requestScope['pages']}页，${requestScope['number']}条记录

            <input type="hidden" name="action" value="listLimit">
            到第<input value="${param['id']}" style="width: 16px" name="id"/>页
            <input type="submit" value="确定">
        </form>
    </div>

</div>

<%--静态包含页脚内容--%>
<%@include file="../common/footer.jsp" %>
</body>
</html>